import { Controller, Get, Post, Param, Body } from '@nestjs/common';
import { ReaderService } from './reader.service';
import { Chapter } from './chapter.entity';

@Controller('reader')
export class ReaderController {
  constructor(private readonly readerService: ReaderService) { }

  // 获取指定书籍的所有章节
  @Get('book/:bookId/chapters')
  async getChapters(@Param('bookId') bookId: number): Promise<Chapter[]> {
    return this.readerService.getChaptersByBook(Number(bookId));
  }

  // 获取某个章节的详细内容
  @Get('chapter/:id')
  async getChapter(@Param('id') id: number): Promise<Chapter> {
    return this.readerService.getChapter(Number(id));
  }

  // 添加章节（用于测试）
  @Post('chapter')
  async createChapter(@Body() chapterData: Partial<Chapter>): Promise<Chapter> {
    return this.readerService.createChapter(chapterData);
  }
}